initrd.img的压缩(制作)及解压的过程

您所在的位置:网站首页 解压 img文件 initrd.img的压缩(制作)及解压的过程

initrd.img的压缩(制作)及解压的过程

2023-08-30 12:33| 来源: 网络整理| 查看: 265

一、启动镜像initrd.img 文件 类RedHat 系统从vmlinuz 核心引导后,会读取initrd.img 启动镜像。该文件中包含驱动模块等信息,是非常重要的文件。不同版本使用的格式不同。 1.RHEL 4.0 版本 采用ext2 文件格式镜像,再通过gzip 压缩:

引用

# file initrd.img initrd.img: gzip compressed data, from Unix, max compression # mv initrd.img initrd.img.gz # gunzip initrd.img.gz # file initrd.img initrd.img: Linux rev 1.0 ext2 filesystem data

2.RHEL 5.0 版本 采用cpio 打包镜像,再通过gzip 压缩:

引用

# file initrd.img initrd.img: gzip compressed data, from Unix, max compression # mv initrd.img initrd.img.gz # gunzip initrd.img.gz # file initrd.img initrd.img: ASCII cpio archive (SVR4 with no CRC)

3.RHEL 6.2 版本 RHEL 6.0 - 6.2 都采用与RHEL 5.0 相同的格式进行打包,但从6.2版本开始,改用LZMA 进行压缩。详见:Release Notes for Red Hat Enterprise Linux 6.2 Edition 2。 如下:

引用

# file initrd.img initrd.img: LZMA compressed data, streamed

※ 注意,若在低于RHEL 6.2 版本下执行file 命令,可能无法识别LZMA 压缩格式:

引用

# file initrd.img initrd.img: data

这时,可把file 软件包升级到5.04-13.el6 即可。 二、xz 工具简介 xz 工具是LZMA 压缩算法的一个实现。具体可见:Wikipedia

引用

xz is a lossless data compression file format incorporating theLZMA2 compression algorithm. While xz can only support one file the convention is to bundle a file that is an archive itself, such as those created by the tar or cpio Unix programs. The original 7zip program implementing LZMA2 compression achieved small files (at the cost of speed compared to gzip or bzip2), but also created its own unique archive format which was Windows-centric and did not support Unix functionality; xz is essentially a stripped down 7zip with little archive format functionality, that compresses a single file (as opposed to 7zip's more complex capabilities like concatenating & compressing entire directories). 7-Zip supports xz since version 9.04 beta (stable since 9.20)

可见,Windows 下可使用7-Zip 打开.xz 文件。LZMA 算法比Gzip 算法压缩率更高。几个参数:

引用

# xz --help Usage: xz [OPTION]... [FILE]... Compress or decompress FILEs in the .xz format. Mandatory arguments to long options are mandatory for short options too.   -z, --compress      force compression   -d, --decompress    force decompression   -t, --test          test compressed file integrity   -l, --list          list information about files   -k, --keep          keep (don't delete) input files   -f, --force         force overwrite of output file and (de)compress links   -c, --stdout        write to standard output and don't delete input files   -0 .. -9            compression preset; 0-2 fast compression, 3-5 good                       compression, 6-9 excellent compression; default is 6   -e, --extreme       use more CPU time when encoding to increase compression                       ratio without increasing memory usage of the decoder

三、手动修改initrd.img 文件 解压:

(RHEL8文件格式支持该种方式,亲测可用)

xz -dc initrd.img | cpio -id

压缩:  

# find . | cpio -c -o | xz -9 --format=lzma > initrd.img

三、补充tar.lzma 由于LZMA具有优秀的压缩率及占用资源少的特点,越来越多的工具采用lzma进行打包,后缀名为:tar.lzma。 对于Fedora 11 及以后的版本,可以使用下面的命令操作: 压缩  

# tar cfv backup.tar.lzma a/dir --lzma

解压:  

# tar xfv backup.tar.lzma --lzma

如果是CentOS 5.3 等老版本,需要安装独立的lzma 工具或用xz 进行:  压缩:  

# tar cv a/dir | lzma -c -z > backup.tar.lzma

解压(两个方式都可以):  

# cat backup.tar.lzma | lzma -d | tar xv  # xz -dc backup.tar.lzma | tar xvf -

 

1."gunzip initrd.img-2.6.27-7-generic.gz",得到一个未压缩的initrd.img-2.6.27-7-generic 2. ”cpio -iv 



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3